package com.devunion.salon.dataload;

import com.devunion.salon.core.model.InventoryDepartment;
import com.devunion.salon.core.model.Vendor;
import com.devunion.salon.core.model.BaseProduct;
import com.devunion.salon.core.model.Product;
import org.springframework.context.ApplicationContext;

import javax.persistence.EntityManager;

/**
 * @author spetrakovsky
 */
public class ProductsLoader implements EntityLoader {

    /**
     * Load 200 Products, 3 vendors and 2 types
     */
    public void loadEntityes(ApplicationContext context, EntityManager em) {

        InventoryDepartment department1 = new InventoryDepartment();
        department1.setName("shampoo");
        em.persist(department1);

        InventoryDepartment department2 = new InventoryDepartment();
        department2.setName("shampoo 2");
        em.persist(department2);

        Vendor vendor1 = new Vendor();
        vendor1.setCode("samsung");
        em.persist(vendor1);

        Vendor vendor2 = new Vendor();
        vendor2.setCode("Microsoft");
        em.persist(vendor2);

        Vendor vendor3 = new Vendor();
        vendor3.setCode("Exigen Services");
        em.persist(vendor3);

        for (int i=0; i < 30; i++ ) {
            Vendor vendor = new Vendor();
            vendor.setCode("Vendor" + i);
            em.persist(vendor);
        }

        for (int i = 1; i <= 200; i++) {
            Product product = new Product();
            product.setBarCode("bar " + i);
            product.setDescription("description " + i);
            if (i % 2 == 0) {
                product.setDiscount(false);
            } else {
                product.setDiscount(true);
            }
            if (i % 2 == 0) {
                product.setInventoryDepartment(department1);
            } else {
                product.setInventoryDepartment(department2);
            }

            product.setMarkup(0.0f);
            product.setName("product name " + i);
            product.setPrice(.5f * i);
            if (i % 2 == 0) {
                product.setPriceOverrides(true);
            } else {
                product.setPriceOverrides(false);
            }
            product.setQty(i);
            product.setRetailPrice(0.7f * i);
            if (i % 2 == 0) {
                product.setTaxable(true);
            } else {
                product.setTaxable(false);
            }
            product.setUom("oz");
            if (i % 3 == 0) {
                product.setVendor(vendor1);
            } else if (i % 2 == 0) {
                product.setVendor(vendor2);
            } else {
                product.setVendor(vendor3);
            }
            em.persist(product);
        }
    }
}
